<template>
    <div class="htmleaf-container">
        <div class="wrapper">
            <div class="container">
                <h1>亿 点 红 包 管 理 后 台</h1>

                <div class="form">
                    <input v-model='userName' type="text" placeholder="用户名" @keyup.enter="doLogin()">
                    <input v-model='passWord' type="password" placeholder="密码" @keyup.enter="doLogin()">
                    <button type="submit" id="login-button" @click='doLogin()' @keyup.enter="doLogin()">登录</button>
                </div>
            </div>

            <ul class="bg-bubbles">
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
    </div>
</template>

<script>
    import { mapActions, mapState } from 'vuex'
    export default {
        data() {
            return {
                userName: '',
                passWord: ''
            }
        },
        created: function () {
            let token = sessionStorage.token;
            if (token !== undefined) {
                this.$router.push('/Home');
            }
        },
        methods: {
            doLogin() {
                if (this.userName == '' || this.passWord == '') {
                    this.$message.warning('请输入账号和密码!');
                } else {
                    this.login({
                        name: this.userName,
                        password: this.passWord,
                        code: 'com_sxluckyking_appManage'
                    }).then((data) => {
                        if (data.code === 200) {
                            console.log(data);
                            let loginResult = data.data;
                            let key = loginResult.key;
                            let token = loginResult.token;
                            sessionStorage.setItem("key", key);
                            sessionStorage.setItem("token", token);
                            if (data.data.sysUser.nick) {
                                sessionStorage.setItem("user", data.data.sysUser.nick);
                            } else {
                                sessionStorage.setItem("user", "请设置用户名");
                            }
                            sessionStorage.setItem("id", data.data.sysUser.id);
                            sessionStorage.setItem("password", data.data.sysUser.password);
                            if (data.data.sysUser.roles && data.data.sysUser.roles && data.data.sysUser.roles.length > 0) {
                                sessionStorage.setItem("rule", data.data.sysUser.roles[0].name);
                            }
                            sessionStorage.setItem("username", data.data.sysUser.name);
                            if (data.data.sysUser.photo) {
                                sessionStorage.setItem("photo", data.data.sysUser.photo);
                            } else {
                                sessionStorage.setItem("photo", "../static/img/avatar5.png");
                            }
                            this.$router.push('/Home');
                        } else {
                            this.$message(data.message);
                        }
                    }).catch((msg) => console.log(msg));
                }
            },
            ...mapActions(['login'])
        }
    }

</script>

<style scoped>
    /*    @import url(http://fonts.useso.com/css?family=Raleway:200,500,700,800);*/
    
    @font-face {
        font-family: 'icomoon';
        src: url('../assets/fonts/icomoon.eot?rretjt');
        src: url('../assets/fonts/icomoon.eot?#iefixrretjt') format('embedded-opentype'), url('../assets/fonts/icomoon.woff?rretjt') format('woff'), url('../assets/fonts/icomoon.ttf?rretjt') format('truetype'), url('../assets/fonts/icomoon.svg?rretjt#icomoon') format('svg');
        font-weight: normal;
        font-style: normal;
    }
    
    [class^="icon-"],
    [class*=" icon-"] {
        font-family: 'icomoon';
        speak: none;
        font-style: normal;
        font-weight: normal;
        font-variant: normal;
        text-transform: none;
        line-height: 1;
        /* Better Font Rendering =========== */
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    body,
    html {
        font-size: 100%;
        padding: 0;
        margin: 0;
    }
    /* Reset */
    
    *,
    *:after,
    *:before {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }
    /* Clearfix hack by Nicolas Gallagher: http://nicolasgallagher.com/micro-clearfix-hack/ */
    
    .clearfix:before,
    .clearfix:after {
        content: " ";
        display: table;
    }
    
    .clearfix:after {
        clear: both;
    }
    
    body {
        background: #f9f7f6;
        color: #404d5b;
        font-weight: 500;
        font-size: 1.05em;
        font-family: "Segoe UI", "Lucida Grande", Helvetica, Arial, "Microsoft YaHei", FreeSans, Arimo, "Droid Sans", "wenquanyi micro hei", "Hiragino Sans GB", "Hiragino Sans GB W3", "FontAwesome", sans-serif;
    }
    
    a {
        color: #2fa0ec;
        text-decoration: none;
        outline: none;
    }
    
    a:hover,
    a:focus {
        color: #74777b;
    }
    
    .htmleaf-container {
        margin: 0 auto;
        text-align: center;
        overflow: hidden;
    }
    
    .htmleaf-content {
        font-size: 150%;
        padding: 1em 0;
    }
    
    .htmleaf-content h2 {
        margin: 0 0 2em;
        opacity: 0.1;
    }
    
    .htmleaf-content p {
        margin: 1em 0;
        padding: 5em 0 0 0;
        font-size: 0.65em;
    }
    
    .bgcolor-1 {
        background: #f0efee;
    }
    
    .bgcolor-2 {
        background: #f9f9f9;
    }
    
    .bgcolor-3 {
        background: #e8e8e8;
    }
    /*light grey*/
    
    .bgcolor-4 {
        background: #2f3238;
        color: #fff;
    }
    /*Dark grey*/
    
    .bgcolor-5 {
        background: #df6659;
        color: #521e18;
    }
    /*pink1*/
    
    .bgcolor-6 {
        background: #2fa8ec;
    }
    /*sky blue*/
    
    .bgcolor-7 {
        background: #d0d6d6;
    }
    /*White tea*/
    
    .bgcolor-8 {
        background: #3d4444;
        color: #fff;
    }
    /*Dark grey2*/
    
    .bgcolor-9 {
        background: #ef3f52;
        color: #fff;
    }
    /*pink2*/
    
    .bgcolor-10 {
        background: #64448f;
        color: #fff;
    }
    /*Violet*/
    
    .bgcolor-11 {
        background: #3755ad;
        color: #fff;
    }
    /*dark blue*/
    
    .bgcolor-12 {
        background: #3498DB;
        color: #fff;
    }
    /*light blue*/
    /* Header */
    
    .htmleaf-header {
        padding: 1em 190px 1em;
        letter-spacing: -1px;
        text-align: center;
    }
    
    .htmleaf-header h1 {
        color: #666;
        font-weight: 600;
        font-size: 2em;
        line-height: 1;
        margin-bottom: 0;
        font-family: "Segoe UI", "Lucida Grande", Helvetica, Arial, "Microsoft YaHei", FreeSans, Arimo, "Droid Sans", "wenquanyi micro hei", "Hiragino Sans GB", "Hiragino Sans GB W3", "FontAwesome", sans-serif;
    }
    
    .htmleaf-header h1 span {
        font-family: "Segoe UI", "Lucida Grande", Helvetica, Arial, "Microsoft YaHei", FreeSans, Arimo, "Droid Sans", "wenquanyi micro hei", "Hiragino Sans GB", "Hiragino Sans GB W3", "FontAwesome", sans-serif;
        display: block;
        font-size: 60%;
        font-weight: 400;
        padding: 0.8em 0 0.5em 0;
        color: #c3c8cd;
    }
    /*nav*/
    
    .htmleaf-demo a {
        color: #1d7db1;
        text-decoration: none;
    }
    
    .htmleaf-demo {
        width: 100%;
        padding-bottom: 1.2em;
    }
    
    .htmleaf-demo a {
        display: inline-block;
        margin: 0.5em;
        padding: 0.6em 1em;
        border: 3px solid #1d7db1;
        font-weight: 700;
    }
    
    .htmleaf-demo a:hover {
        opacity: 0.6;
    }
    
    .htmleaf-demo a.current {
        background: #1d7db1;
        color: #fff;
    }
    /* Top Navigation Style */
    
    .htmleaf-links {
        position: relative;
        display: inline-block;
        white-space: nowrap;
        font-size: 1.5em;
        text-align: center;
    }
    
    .htmleaf-links::after {
        position: absolute;
        top: 0;
        left: 50%;
        margin-left: -1px;
        width: 2px;
        height: 100%;
        background: #dbdbdb;
        content: '';
        -webkit-transform: rotate3d(0, 0, 1, 22.5deg);
        transform: rotate3d(0, 0, 1, 22.5deg);
    }
    
    .htmleaf-icon {
        display: inline-block;
        margin: 0.5em;
        padding: 0em 0;
        width: 1.5em;
        text-decoration: none;
    }
    
    .htmleaf-icon span {
        display: none;
    }
    
    .htmleaf-icon:before {
        margin: 0 5px;
        text-transform: none;
        font-weight: normal;
        font-style: normal;
        font-variant: normal;
        font-family: 'icomoon';
        line-height: 1;
        speak: none;
        -webkit-font-smoothing: antialiased;
    }
    /* footer */
    
    .htmleaf-footer {
        width: 100%;
        padding-top: 10px;
    }
    
    .htmleaf-small {
        font-size: 0.8em;
    }
    
    .center {
        text-align: center;
    }
    /****/
    
    .related {
        width: 100%;
        position: absolute;
        top: 100%;
        left: 0;
        color: #fff;
        background: #333;
        text-align: center;
        font-size: 1.25em;
        padding: 0.5em 0;
        overflow: hidden;
    }
    
    .related>a {
        vertical-align: top;
        width: calc(100% - 20px);
        max-width: 340px;
        display: inline-block;
        text-align: center;
        margin: 20px 10px;
        padding: 25px;
        font-family: "Segoe UI", "Lucida Grande", Helvetica, Arial, "Microsoft YaHei", FreeSans, Arimo, "Droid Sans", "wenquanyi micro hei", "Hiragino Sans GB", "Hiragino Sans GB W3", "FontAwesome", sans-serif;
    }
    
    .related a {
        display: inline-block;
        text-align: left;
        margin: 20px auto;
        padding: 10px 20px;
        opacity: 0.8;
        -webkit-transition: opacity 0.3s;
        transition: opacity 0.3s;
        -webkit-backface-visibility: hidden;
    }
    
    .related a:hover,
    .related a:active {
        opacity: 1;
    }
    
    .related a img {
        max-width: 100%;
        opacity: 0.8;
        border-radius: 4px;
    }
    
    .related a:hover img,
    .related a:active img {
        opacity: 1;
    }
    
    .related h3 {
        font-family: "Microsoft YaHei", sans-serif;
    }
    
    .related a h3 {
        font-weight: 300;
        margin-top: 0.15em;
        color: #fff;
    }
    /* icomoon */
    
    .icon-htmleaf-home-outline:before {
        content: "\e5000";
    }
    
    .icon-htmleaf-arrow-forward-outline:before {
        content: "\e5001";
    }
    
    @media screen and (max-width: 50em) {
        .htmleaf-header {
            padding: 3em 10% 4em;
        }
        .htmleaf-header h1 {
            font-size: 2em;
        }
    }
    
    @media screen and (max-width: 40em) {
        .htmleaf-header h1 {
            font-size: 1.5em;
        }
    }
    
    @media screen and (max-width: 30em) {
        .htmleaf-header h1 {
            font-size: 1.2em;
        }
    }
    /*    @import url(http://fonts.useso.com/css?family=Source+Sans+Pro:200,300);*/
    
    * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
        font-weight: 300;
    }
    
    body {
        font-family: 'Source Sans Pro', sans-serif;
        color: white;
        font-weight: 300;
    }
    
    body::-webkit-input-placeholder {
        /* WebKit browsers */
        font-family: 'Source Sans Pro', sans-serif;
        color: white;
        font-weight: 300;
    }
    
    body:-moz-placeholder {
        /* Mozilla Firefox 4 to 18 */
        font-family: 'Source Sans Pro', sans-serif;
        color: white;
        opacity: 1;
        font-weight: 300;
    }
    
    body::-moz-placeholder {
        /* Mozilla Firefox 19+ */
        font-family: 'Source Sans Pro', sans-serif;
        color: white;
        opacity: 1;
        font-weight: 300;
    }
    
    body:-ms-input-placeholder {
        /* Internet Explorer 10+ */
        font-family: 'Source Sans Pro', sans-serif;
        color: white;
        font-weight: 300;
    }
    
    .wrapper {
        background: #50a3a2;
        background: -webkit-linear-gradient(top left, #50a3a2 0%, #53e3a6 100%);
        background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
        opacity: 0.8;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
    
    .wrapper.form-success .container h1 {
        -webkit-transform: translateY(85px);
        -ms-transform: translateY(85px);
        transform: translateY(85px);
    }
    
    .container {
        max-width: 600px;
        padding: 50px;
        height: 360px;
        text-align: center;
        position: absolute;
        background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
        top: 50%;
        left: 50%;
        margin: -180px 0 0 -300px
    }
    
    .container h1 {
        font-size: 40px;
        -webkit-transition-duration: 1s;
        transition-duration: 1s;
        -webkit-transition-timing-function: ease-in-put;
        transition-timing-function: ease-in-put;
        font-weight: 200;
    }
    
    .form {
        padding: 60px 0;
        position: relative;
        z-index: 2;
    }
    
    .form input {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        outline: 0;
        border: 1px solid rgba(255, 255, 255, 0.4);
        background-color: rgba(255, 255, 255, 0.2);
        width: 250px;
        border-radius: 3px;
        padding: 10px 15px;
        margin: 0 auto 10px auto;
        display: block;
        text-align: center;
        font-size: 18px;
        color: white;
        -webkit-transition-duration: 0.25s;
        transition-duration: 0.25s;
        font-weight: 300;
    }
    
    .form input:hover {
        background-color: rgba(255, 255, 255, 0.4);
    }
    
    .form input:focus {
        background-color: white;
        width: 300px;
        color: #53e3a6;
    }
    
    .form button {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        outline: 0;
        background-color: white;
        border: 0;
        padding: 10px 15px;
        color: #53e3a6;
        border-radius: 3px;
        width: 250px;
        cursor: pointer;
        font-size: 18px;
        -webkit-transition-duration: 0.25s;
        transition-duration: 0.25s;
    }
    
    .form button:hover {
        background-color: #f5f7f9;
    }
    
    .bg-bubbles {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
    }
    
    .bg-bubbles li {
        position: absolute;
        list-style: none;
        display: block;
        width: 40px;
        height: 40px;
        background-color: rgba(255, 255, 255, 0.15);
        bottom: -160px;
        -webkit-animation: square 25s infinite;
        animation: square 25s infinite;
        -webkit-transition-timing-function: linear;
        transition-timing-function: linear;
    }
    
    .bg-bubbles li:nth-child(1) {
        left: 10%;
    }
    
    .bg-bubbles li:nth-child(2) {
        left: 20%;
        width: 80px;
        height: 80px;
        -webkit-animation-delay: 2s;
        animation-delay: 2s;
        -webkit-animation-duration: 17s;
        animation-duration: 17s;
    }
    
    .bg-bubbles li:nth-child(3) {
        left: 25%;
        -webkit-animation-delay: 4s;
        animation-delay: 4s;
    }
    
    .bg-bubbles li:nth-child(4) {
        left: 40%;
        width: 60px;
        height: 60px;
        -webkit-animation-duration: 22s;
        animation-duration: 22s;
        background-color: rgba(255, 255, 255, 0.25);
    }
    
    .bg-bubbles li:nth-child(5) {
        left: 70%;
    }
    
    .bg-bubbles li:nth-child(6) {
        left: 80%;
        width: 120px;
        height: 120px;
        -webkit-animation-delay: 3s;
        animation-delay: 3s;
        background-color: rgba(255, 255, 255, 0.2);
    }
    
    .bg-bubbles li:nth-child(7) {
        left: 32%;
        width: 160px;
        height: 160px;
        -webkit-animation-delay: 7s;
        animation-delay: 7s;
    }
    
    .bg-bubbles li:nth-child(8) {
        left: 55%;
        width: 20px;
        height: 20px;
        -webkit-animation-delay: 15s;
        animation-delay: 15s;
        -webkit-animation-duration: 40s;
        animation-duration: 40s;
    }
    
    .bg-bubbles li:nth-child(9) {
        left: 25%;
        width: 10px;
        height: 10px;
        -webkit-animation-delay: 2s;
        animation-delay: 2s;
        -webkit-animation-duration: 40s;
        animation-duration: 40s;
        background-color: rgba(255, 255, 255, 0.3);
    }
    
    .bg-bubbles li:nth-child(10) {
        left: 90%;
        width: 160px;
        height: 160px;
        -webkit-animation-delay: 11s;
        animation-delay: 11s;
    }
    
    @-webkit-keyframes square {
        0% {
            -webkit-transform: translateY(0);
            transform: translateY(0);
        }
        100% {
            -webkit-transform: translateY(-700px) rotate(600deg);
            transform: translateY(-700px) rotate(600deg);
        }
    }
    
    @keyframes square {
        0% {
            -webkit-transform: translateY(0);
            transform: translateY(0);
        }
        100% {
            -webkit-transform: translateY(-700px) rotate(600deg);
            transform: translateY(-700px) rotate(600deg);
        }
    }
</style>